// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   IVL_INTImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.INT;
import com.sunwayhorizo.health.hl7.datatypes.IVL_INT;
import com.sunwayhorizo.health.hl7.datatypes.SET_INT;
import com.sunwayhorizo.health.hl7.datatypes.ST;
import com.sunwayhorizo.health.hl7.datatypes.TYPE;

import java.util.Set;



// Referenced classes of package oracle.apps.ctb.hl7.types.common:
//            ANYImpl, BLImpl, CSImpl, INTImpl, 
//            NullFlavorImpl, TYPEImpl

public class IVL_INTImpl extends ANYImpl
    implements IVL_INT
{

    public static final String RCS_ID = "$Header: IVL_INTImpl.java 115.36 2005/09/16 09:23:57 amchanda noship $";
    protected INT _low;
    protected INT _high;
    protected BL _lowClosed;
    protected BL _highClosed;
    protected INT _center;
    protected INT _width;
    private static final IVL_INT nullNI = new IVL_INTImpl(CSImpl.valueOf("NI"));
    private static final IVL_INT nullOTH = new IVL_INTImpl(CSImpl.valueOf("OTH"));
    private static final IVL_INT nullNINF = new IVL_INTImpl(CSImpl.valueOf("NINF"));
    private static final IVL_INT nullPINF = new IVL_INTImpl(CSImpl.valueOf("PINF"));
    private static final IVL_INT nullUNK = new IVL_INTImpl(CSImpl.valueOf("UNK"));
    private static final IVL_INT nullASKU = new IVL_INTImpl(CSImpl.valueOf("ASKU"));
    private static final IVL_INT nullNAV = new IVL_INTImpl(CSImpl.valueOf("NAV"));
    private static final IVL_INT nullMSK = new IVL_INTImpl(CSImpl.valueOf("MSK"));
    private static final IVL_INT nullNA = new IVL_INTImpl(CSImpl.valueOf("NA"));
    private static final IVL_INT nullNASK = new IVL_INTImpl(CSImpl.valueOf("NASK"));

    public static IVL_INT valueOf(INT int1, BL bl, INT int2, BL bl1)
    {
        return new IVL_INTImpl(int1, bl, int2, bl1);
    }

    public static IVL_INT nullIVL_INT()
    {
        return new IVL_INTImpl(null);
    }

    private IVL_INTImpl(INT int1, BL bl, INT int2, BL bl1)
    {
        if(bl == null || int1 == null || int2 == null || bl1 == null)
        {
            if(bl == null)
                throw ANYImpl.newNullException("IVL<INT>", "constructor", "lowClosed");
            if(int1 == null)
                throw ANYImpl.newNullException("IVL<INT>", "constructor", "low");
            if(int2 == null)
                throw ANYImpl.newNullException("IVL<INT>", "constructor", "high");
            if(bl1 == null)
                throw ANYImpl.newNullException("IVL<INT>", "constructor", "highClosed");
        }
        _lowClosed = bl;
        _low = int1;
        _high = int2;
        _highClosed = bl1;
    }

    private IVL_INTImpl(CS cs)
    {
        super(true, cs);
        _low = INTImpl.nullINT(NullFlavorImpl.NI);
        _high = INTImpl.nullINT(NullFlavorImpl.NI);
        _lowClosed = BLImpl.nullBL(NullFlavorImpl.NI);
        _highClosed = BLImpl.nullBL(NullFlavorImpl.NI);
    }

    public TYPE dataType()
    {
        return com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.IVL_INT;
    }

    public ST literal()
    {
        throw ANYImpl.newUnsupportedException("IVL<INT>", "literal");
    }

    public INT low()
    {
        if(isNull().isTrue())
            return INTImpl.nullINT();
        else
            return _low;
    }

    public INT high()
    {
        if(isNull().isTrue())
            return INTImpl.nullINT();
        else
            return _high;
    }

    public BL lowClosed()
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return _lowClosed;
    }

    public BL highClosed()
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return _highClosed;
    }

    public INT width()
    {
        if(isNull().isTrue())
            return INTImpl.nullINT();
        return _width;
    }

    public INT center()
    {
        throw ANYImpl.newUnsupportedException("IVL<INT>", "center");
    }

    public BL contains(INT int1)
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return low().lessOrEqual(int1).or(low().isNull()).and(int1.lessOrEqual(high()).or(high().isNull())).and(low().equal(int1).implies(lowClosed())).and(high().equal(int1).implies(highClosed()));
    }

    public BL isEmpty()
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return width().isZero().and(lowClosed().and(highClosed()).not());
    }

    public BL nonEmpty()
    {
        return isEmpty().not();
    }

    public BL notEmpty()
    {
        return isEmpty().not();
    }

    public BL contains(SET_INT set_int)
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        if(set_int instanceof IVL_INT)
        {
            IVL_INT ivl_int = (IVL_INT)set_int;
            return contains(ivl_int.low()).and(contains(ivl_int.high()));
        }
        if(set_int instanceof SET_INT)
            return contains(((SET_INT) (set_int.hull())));
        else
            return BLImpl.FALSE;
    }

    public INT cardinality()
    {
        throw ANYImpl.newUnsupportedException("IVL<INT>", "cardinality");
    }

    public SET_INT union(INT int1)
    {
        throw ANYImpl.newUnsupportedException("IVL<INT>", "union");
    }

    public SET_INT union(SET_INT set_int)
    {
        if(set_int instanceof IVL_INT)
        {
            IVL_INT ivl_int = (IVL_INT)set_int;
            if(overlaps(ivl_int).isTrue())
                return hull(ivl_int);
        } else
        {
            if(contains(set_int.hull()).isTrue())
                return this;
            if(set_int.contains(this).isTrue())
                return set_int;
        }
        throw ANYImpl.newUnsupportedException("IVL<INT>", "union");
    }

    public SET_INT except(INT int1)
    {
        throw ANYImpl.newUnsupportedException("IVL<INT>", "except");
    }

    public SET_INT except(SET_INT set_int)
    {
        throw ANYImpl.newUnsupportedException("IVL<INT>", "except");
    }

    public SET_INT intersection(SET_INT set_int)
    {
        throw ANYImpl.newUnsupportedException("IVL<INT>", "intersection");
    }

    public IVL_INT intersection(IVL_INT ivl_int)
    {
        throw ANYImpl.newUnsupportedException("IVL<INT>", "intersection");
    }

    public IVL_INT hull(IVL_INT ivl_int)
    {
        throw ANYImpl.newUnsupportedException("IVL<INT>", "hull");
    }

    public BL overlaps(IVL_INT ivl_int)
    {
        if(isNull().isTrue())
            return BLImpl.nullBL();
        else
            return contains(ivl_int.low()).or(contains(ivl_int.high())).or(ivl_int.contains(low())).or(ivl_int.contains(high()));
    }

    public IVL_INT hull()
    {
        return this;
    }

    public IVL_INT nextTo(INT int1)
    {
        if(int1.lessOrEqual(high()).isTrue())
        {
            if(int1.equal(high()).isTrue())
            {
                if(highClosed().isFalse())
                    return this;
                else
                    return nullIVL_INT();
            } else
            {
                return this;
            }
        } else
        {
            return nullIVL_INT();
        }
    }

    public IVL_INT nextAfter(INT int1)
    {
        IVL_INT ivl_int = nextTo(int1);
        if(ivl_int.isNull().isFalse() && ivl_int.contains(int1).isFalse())
            return this;
        else
            return nullIVL_INT();
    }

    public BL equal(ANY any)
    {
        if(!(any instanceof IVL_INT))
            return BLImpl.FALSE;
        IVL_INT ivl_int = (IVL_INT)any;
        if(isNull().or(any.isNull()).isTrue())
            return BLImpl.FALSE;
        else
            return lowClosed().equal(ivl_int.lowClosed()).or(lowClosed().isNull().and(ivl_int.lowClosed().isNull())).and(highClosed().equal(ivl_int.highClosed()).or(highClosed().isNull().and(ivl_int.highClosed().isNull()))).and(low().equal(ivl_int.low()).or(low().isNull().and(ivl_int.low().isNull()))).and(high().equal(ivl_int.high()).or(high().isNull().and(ivl_int.high().isNull())));
    }

    public SET_INT promotion(INT int1)
    {
        throw ANYImpl.newUnsupportedException("IVL<INT>", "promotion");
    }

    public INT demotion()
    {
        throw ANYImpl.newUnsupportedException("IVL<INT>", "demotion");
    }

    public Set toSet()
    {
        throw ANYImpl.newUnsupportedException("IVL<INT>", "toSet");
    }

//    public XMLNode[] writeXML(XMLDocument xmldocument, String s)
//        throws Hl7Exception
//    {
//        try
//        {
//            XMLElement xmlelement = (XMLElement)xmldocument.createElement(s);
//            if(low() != null && low().isNull().isFalse())
//            {
//                XMLNode xmlnode = ((INTImpl)low()).writeXML(xmldocument, "low")[0];
//                if(!lowClosed().isNull().isTrue())
//                    ((XMLElement)xmlnode).setAttribute("inclusive", lowClosed().literal().stringValue());
//                xmlelement.appendChild(xmlnode);
//            }
//            if(high() != null && high().isNull().isFalse())
//            {
//                XMLNode xmlnode1 = ((INTImpl)high()).writeXML(xmldocument, "high")[0];
//                if(!highClosed().isNull().isTrue())
//                    ((XMLElement)xmlnode1).setAttribute("inclusive", highClosed().literal().stringValue());
//                xmlelement.appendChild(xmlnode1);
//            }
//            return (new XMLNode[] {
//                xmlelement
//            });
//        }
//        catch(Exception exception)
//        {
//            throw new Hl7Exception(exception);
//        }
//    }

    public static IVL_INT nullIVL_INT(CS cs)
    {
        String s = null;
        if(cs == null || cs.literal().stringValue() == null || cs.isNull().isTrue())
            s = "NI";
        else
            s = cs.literal().stringValue();
        if(s.equals("NI"))
            return nullNI;
        if(s.equals("OTH"))
            return nullOTH;
        if(s.equals("NINF"))
            return nullNINF;
        if(s.equals("PINF"))
            return nullPINF;
        if(s.equals("UNK"))
            return nullUNK;
        if(s.equals("ASKU"))
            return nullASKU;
        if(s.equals("NAV"))
            return nullNAV;
        if(s.equals("MSK"))
            return nullMSK;
        if(s.equals("NA"))
            return nullNA;
        if(s.equals("NASK"))
            return nullNASK;
        else
            return nullNI;
    }

}
